<template>
  <div
    id="msg"
    :style="[{'transform':'rotate('+deg+')'},{'backgroundColor':color}]"
    @click="seeAdvice"
  >
    <transition appear name="fadeIn">
      <div class="Box">
        <div class="O"></div>
        <p style="font-weight:200;font-size:13px;color:#666;line-height:20px">{{time|format}}</p>
        <div>
          <span style="color:#fff;font-weight:200;font-size:14px;margin-right:3px">作者：{{username}}</span>
          <button v-if="limit" class="del" @click="delAdvice">删除</button>
        </div>

        <span class="adviceContent">{{advice}}</span>
      </div>
    </transition>
  </div>
</template>

<script>
import Bus from "../bus"
import { formatTime } from "../formatTime";

export default {
  props:["username","advice","time","id","realname"],
  // 这里username和realname反了
  data() {
    return {
      rainfallColor: [
        "rgba(255, 0, 0,.6)",
        "rgba(255, 165, 0,.6)",
        "rgba(255, 255, 0,.6)",
        "rgba(0, 255, 0,.6)",
        "rgba(0, 127, 255,.6)",
        "rgba(0, 0, 255,.6)",
        "rgba(139, 0, 255,.6)",
      ],
    };
  },
   filters: {
    format(val) {
      return formatTime(parseInt(val));
    },
  },
  computed: {
    deg() {
      return Math.floor((0.5 - Math.random()) * 40) + "deg";
    },
    color() {
      let index = Math.ceil(Math.random() * 7);
      return this.rainfallColor[index - 1];
    },
    //权限设置
    limit(){
      if(this.$store.getters.user.status==="876ea4f21078c7d38e3b0bdc74a"||this.$store.getters.user.username===this.realname){
        return true
      }else{
        return false
      }
    }
  },
  methods: {
    seeAdvice() {
      console.log(this.color);
      Bus.$emit("startSeeAdvice",{
        advice:this.advice,
        color:this.color,
        username:this.username
      })
    },
    delAdvice(){
      this.$emit("IfDel")
    }
  },
};
</script>

<style lang="less" scoped>
@import url("../css/comment/animate.css");
#msg {
  position: relative;
  width: 200px;
  height: 200px;
  margin: 23px;
  display: inline-block;
  padding: 35px 15px;
  box-shadow: 0 0 5px 2px rgba(0, 0, 0, 0.5);
  transition: all 0.5s;
  box-sizing: border-box;
  vertical-align: top;
  border-radius: 35px;
  .Box {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 5;
    overflow: hidden;
  }
  .del {
    background-color: transparent;
    border: 1px solid #00000088;
    width: 60px;
    height: 30px;
    margin-bottom: 2px;
    border-radius: 30px;
    transition: all 0.3s;
    font-weight: 200;
  // cursor: url("../assets/img/cur/mais.png"), default;

    &:hover {
      background-color: red;
      color: #fff;
    }
  }
}
#msg:hover {
  box-shadow: 5px 5px 5px 3px rgba(0, 0, 0, 0.5);
  transform: scale(1.1) !important;
}
#msg span {
  margin-top: 25px;
  height: 40px;
  border-bottom: 1px solid black;
  letter-spacing: 1px;
  line-height: 27px;
}
.O {
  position: absolute;
  width: 20px;
  height: 20px;
  border-radius: 20px;
  background-color: #fff;
  top: 10px;
  left: 20px;
}
</style>